<template>
    <div class="box-content" v-if="courseResource && resSubType !== 'AICC_AU'">
        <div class="box-table clearfix" style="width: 100%;">
            <div style="width: 40px;height: 40px;float:left;" @click="unfold()">
                <i class="more-icon icon-left" :class="{'cur' : moreList != false}"></i>
            </div>
            <div class="learning-title-box" @click="beforeLearn(resSubType)">
                <p class="font-size15 word-clamp-2">{{ courseResource.resTitle }}</p>
<!--                <p class="font-size15 re-rating-btn" v-if="reRatingBtn()" @click.stop="reRatingConfirm()">{{ $t("exam_rpt_re_rating") }}</p>-->  <!--屏蔽掉重新评分-->
                <div class="font-size11 color666 margin-top10" style="display: flex;flex-wrap:wrap;justify-content: space-between;line-height: 24px;">
                    <div style="display: inline-block;margin-right: 10px;"><span>{{ conType[resSubType] }}</span></div>
                </div>
            </div>
            <div class="learning-icon-box box-table-cell" v-if="isShowLearnBtn()" @click="beforeLearn(resSubType)">
                <i class="start-learning-icon" :class="{'cur': coloring()}"></i>
            </div>
        </div>
        <!-- 测验 -->
        <div class="box-content-02 font-size11" v-if="resSubType == 'TST' || resSubType == 'DXT'" @click="beforeLearn(resSubType)" >
            <p>{{ $t("mod_best_score") }}：{{ (courseResource.traineeTestDetailDTO.movMaxScore && courseResource.traineeTestDetailDTO.movMaxScore > -1) ? courseResource.traineeTestDetailDTO.movMaxScore : 0 }}</p><!--最佳分数-->
            <p>{{ $t("mod_full_score") }}：{{ courseResource.traineeTestDetailDTO.maxScore }}</p><!--满分-->
            <p>{{ $t("mod_pass_rate") }}：{{ courseResource.traineeTestDetailDTO.passScore }}%</p><!--合格率-->
            <p>{{ $t("mod_time_limit_requirement") }}：{{ courseResource.modRequiredTime && courseResource.modRequiredTime > 0 ? courseResource.modRequiredTime /60 + $t("mod_time_minute") : $t("mod_unlimited_time")  }}</p> <!--限时时间-->
        </div>
        <!--视频点播-->
        <div class="font-size11" v-if="moreList">
            <div class="box-padding-01 margin-top30">
                <!--教材、参考、视频点播、scorm课件-->
                <p>{{ $t("mod_time_account") }}：<span>{{courseResource.learnerTime ? courseResource.learnerTime : '00:00:00' }}</span></p>
                <div v-if="resSubType == 'RDG' || resSubType =='REF' || resSubType =='VOD'  || resSubType == 'AUD' || resSubType =='SCO' || resSubType =='SCLASS'">
                    <!--我的学习时长-->
                    <div>
                    <!--    至少需要学习/分钟才能完成任务  数据没有返回-->
                        <p class="color999"
                           style="margin: 0;"
                           v-if="
                            courseResource.modRequiredTime
                            && courseResource.modRequiredTime != ''
                            && resSubType != 'SCO'
                            &&fmtHours1(courseResource.modRequiredTime)">
                            {{ $t('mod_time_account_tips', {'value': fmtHours1(courseResource.modRequiredTime)}) }}
                        </p>
                    </div>
                </div>
                <div v-if="resSubType=='SCO' && courseResource.traineeTestDetailDTO.movMaxScore > 0">
                    <p style="margin-top: 20px;">{{ $t("mod_full_score") }}：{{ courseResource.traineeTestDetailDTO.maxScore }}</p><!--满分-->
                    <p style="margin: 0 0 5px;">{{ $t("mod_pass_score") }}：{{ courseResource.traineeTestDetailDTO.passScore }}</p><!--合格分-->
                </div>
                <!--学习期限/提交期限/至/不限-->
                <p><span v-if="resSubType!= 'ACE'">{{ $t("mod_study_duration") }}：</span><span v-if="resSubType == 'ACE'">{{ $t("mod_submit_duration") }}：</span>{{ courseResource.beginTime | formatDate }} {{ $t("time_to") }} {{ courseResource.endTime === '9999-12-31 23:59:59' ? $t("cos_unlimited") : subTime(courseResource.endTime) }}</p>
                <!--提交截止时间/天(从课程开始日期算起)/未指定    未返回-->
                <!-- 提交方式 匿名提交ANONYMOUS  实名提交REALNAME -->
                <p v-if="resSubType == 'ACE'"><span >{{ $t("mod_submit_type") }}:</span><span style="padding-left:10px">{{modSubmitType === "REALNAME"? $t('real_name_submitted'):$t('anonymous_submission')}}</span></p>
               <!-- <p v-if="resSubType == 'ASS'">{{ $t("mod_submit_deadline") }}：<span v-if="mod.ass_due_date_day != 0">{{ mod.ass_due_date_day }}{{ $t("mod_content_eff_duration") }}</span><span v-if="mod.ass_due_date_day == 0 && mod.ass_due_datetime">{{ mod.ass_due_datetime | substringTime }}</span><span v-if="!mod.ass_due_datetime">{{ $t("mod_files_null") }}</span></p>-->
                <!--最近访问/提交时间-->
                <p><span v-if="resSubType != 'ACE'">{{ $t("mod_last_access_time") }}：</span><span v-if="resSubType == 'ACE'">{{ $t("mod_submit_time") }}：</span><span v-if="courseResource.lastTime">{{courseResource.lastTime | conversionTime }}</span></p>
                <!--状态-->
                <p>{{ $t("mod_status") }}：{{ courseResource.movStatus ? getAppStatusStr(courseResource.movStatus,resSubType ) : '--' }}</p>
            </div>
            <!--允许打开次数/无限制/允许提交次数/简介-->
            <div class="box-padding-02 margin-top30" v-if="resSubType == 'TST' || resSubType == 'DXT'">
                <p>{{ $t("mod_test_open_times") }}：{{ courseResource.traineeTestDetailDTO && courseResource.traineeTestDetailDTO.totalOpen || 0}} / {{ courseResource.traineeTestDetailDTO.maxUsrOpen == 0 ? $t("mod_unlimit") : courseResource.traineeTestDetailDTO.maxUsrOpen }}</p>
                <p>{{ $t("mod_test_times") }}：{{ courseResource.traineeTestDetailDTO && courseResource.traineeTestDetailDTO.totalAttempt || 0 }} / {{ courseResource.traineeTestDetailDTO.maxUsrAttempt == 0 ? $t("mod_test_unlimit") : courseResource.traineeTestDetailDTO.maxUsrAttempt }}</p>
            </div>
            <div class="box-padding-02 margin-top30" v-if="courseResource.desc && courseResource.desc != 'null'">
                <p>{{ $t("mod_desc") }}：{{ courseResource.desc }}</p>
            </div>
        </div>
<!--        <div class="box-content-02 font-size11">-->
<!--            <p class="download" v-if="$store.state.config.plus-->
<!--                                             && courseResource.res_subtype === 'VOD'-->
<!--                                             && courseResource.res_src_type === 'FILE'-->
<!--                                             && mod.mod_download_ind === 1"-->
<!--               @click="download(courseResource.res_id, courseResource.res_title)">-->
<!--                {{ downloadStatusDesc(courseResource.res_id) }}-->
<!--            </p>-->
<!--        </div>-->
        <p class="word-btn-01 box-padding-03" v-if="testReportBtn()" @click="JumpTestingReport()">{{ $t("exam_report") }}</p><!--测验报告-->
        <!--tips-->
        <div class="toast-box-03" v-if="assTip">
            <p class="toast-box-03-title">{{ tipsType }}</p>
        </div>
        <van-dialog
        v-model="tstErrorTips"
        :title="tipsType"
        :confirm-button-text="$t('sure')"
        >
        </van-dialog>
        <van-dialog
        v-model="examTip"
        show-cancel-button
        :title="examInfo ? examInfo.title : ''"
        :cancelButtonText="$t('cancel')"
        :confirm-button-text="$t('exam_start')"
        @confirm="startExam"
        class="exam-dialog"
        >
            <div style="font-size: 15px; color: #1a1a1a;margin-left: 20px;">
                <div>{{ $t("mod_topic_total") }}：{{examList.length}}</div><!--题目总数-->
                <div style="padding: 10px 0 0;">{{ $t("mod_total_score") }}：{{examInfo.maxScore}}</div><!--总分-->
                <div style="padding: 10px 0 0;word-wrap:break-word;">{{ $t("mod_time_limit") }}：{{ examInfo.timeLimit > 0 ? examInfo.timeLimit / 60 / 1000 : $t("mod_unlimited_time") }}</div><!--限时/不限时-->
            </div>
        </van-dialog>
        <van-dialog
        v-model="reviewPopupLayer"
        :title="$t('cos_notice')"
        :confirm-button-text="$t('sure')"
        @confirm="jumpModuleDetail(resSubType)"
        >
            <p style="text-align:center;font-size: 14px;color: #999999;">{{ $t("cos_review_tip") }}</p><!--现在是回顾学习，平台不会记录您的学习结果-->
        </van-dialog>
        <!-- 第一次下载提示 -->
        <van-dialog
        v-model="alterMsg.show"
        :confirm-button-text="$t('sure')"
        :title="alterMsg.firstLine"
        >
            <p style="text-align:center;font-size: 14px;color: #999999;">{{ alterMsg.secondLine }}</p>
        </van-dialog>
        <van-dialog
        v-model="examBeforeTips"
        :show-confirm-button="false"
        :title="$t('modal_title_notice')"
        >
            <div style="font-size: 14px; color: #1a1a1a;text-align: center;">
                <span style="color: #999999;">{{$t('get_test_paper')}}</span>
            </div>
        </van-dialog>
    </div>
</template>

<script>
import {Notify, Toast} from 'vant';
import { compareDate, fmtHours1 } from '@/utils/tools';
export default {
    name: 'InformationModule',
    components: {vanToast: Toast, [Notify.Component.name]: Notify.Component},
    props: ['list', 'unregistered', 'tkhId', 'itmId', 'userEntId', 'resId', 'item', 'itmExamInd'],
    data() {
        return {
            examDetail: '',
            assTip: false,
            tstErrorTips: false,
            reRatingTip: false,
            tipsType: '',
            preInfoTip: false, //先修提示层
            preInfo: '', //先修提示
            reviewPopupLayer: false, //回顾提示层
            timeValide: false,
            moreList: false, //展开每个学习单元的详情
            conType: { //模块类型
                TST: this.$t('mod_TST'), //静态测验
                DXT: this.$t('mod_DXT'), //动态测验
                ASS: this.$t('mod_ASS'), //作业
                SVY: this.$t('mod_SVY'), //课程评估问卷
                VOD: this.$t('mod_VOD'), //视频点播
                AUD: this.$t('mod_AUD'), //音频点播
                SCO: this.$t('mod_SCO'), //SCORM课件
                RDG: this.$t('mod_RDG'), //教材
                REF: this.$t('mod_REF'), //参考
                ACE: this.$t('mod_ACE'), // 问卷最新
                SCLASS: this.$t('SCLASS') // 微课
            },
            alterMsg: {
                show: false,
                firstLine: '',
                secondLine: ''
            },
            curLan: window.localStorage.getItem('globalLang'),
            examInfo: {}, //考试信息
            examTip: false,
            examList: [], //试题信息,
            examDoing: true,
            modSubmitType: '',
            examBeforeTips: false, //考试之前获取试卷提示
            questionType: ''
        };
    },
    methods: {
        ...{fmtHours1},
        startExam() {
            this.$axios({
                url: `/app/exam/module/accessTime`,
                method: 'PUT',
                params: {
                    modId: this.examInfo.id
                }
            }).then(res => {
                if (res.data.code === 200) {
                    this.$router.push({path: `/exam/${this.tkhId}/${this.examInfo.id}/${this.itmId}`, query: {itmExamInd: this.itmExamInd, questionType: this.questionType}});
                } else if (res.data.code === 401) {
                    this.assTip = true;
                    this.tipsType = this.$t('cos_num_of_attempts'); //尝试次数已用完
                } else if (res.data.code === 402) {
                    this.assTip = true;
                    this.tipsType = this.$t('has_deleted_learning_record'); //报名记录被删除
                } else {
                    //判断考试是否暂停
                    this.$axios({
                        method: 'PUT',
                        url: `/app/exam/module/accessTime`
                    }).then(res => {
                        if (res.data) { //为true 则被强制暂停
                            Notify({
                                message: this.$t('forced_to_suspend'),
                                color: '#fff',
                                background: '#ffc002'
                            });
                            return false;
                        } else {
                            this.$router.push({path: `/exam/${this.tkhId}/${this.examInfo.id}/${this.itmId}/${this.questionType}`});
                        }
                    });
                }
            });
        },
        JumpTestingReport() {
            let modId = this.modResId;
            let attemptNbr = this.courseResource.traineeTestDetailDTO.totalAttempt || 0;
            this.$router.push({path: `/testingReport/${this.itmId}/${this.tkhId}/${modId}?attemptNbr=${attemptNbr}`});
        },
        /* ps： 现在的this.userEntId 没有返回,采用 window.localStorage.getItem('loginUser') 替代*/
        jumpModuleDetail(moduleType) {
            let isReview = false; //是否为回顾   this.reviewPopupLayer === true ? this.reviewPopupLayer : false 之前这样判断 现在统一不为回顾学习
            switch (moduleType) {
            case 'SCLASS':
                this.$router.push({path: `/sclassContent/${this.tkhId}/${this.itmId}/${this.resId}/${this.courseResource.moduleId}`});
                break;
            case 'RDG':
                //取消当前判断
                /*if (this.courseResource.res_src_type === 'URL' || this.courseResource.res_src_type === 'FILE') {
                    this.$router.push({path: `/teachingMaterial/${this.userEntId}/${this.tkhId}/${courseItmId}/${this.resId}/${this.courseResource.moduleId}`});
                }*/
                this.$router.push({path: `/teachingMaterial/${this.userEntId}/${this.tkhId}/${this.itmId}/${this.resId}/${this.courseResource.moduleId}`});
                break;
            case 'VOD':
                this.$router.push({path: `/vodContent/${this.tkhId}/${this.itmId}/${this.resId}/${this.courseResource.moduleId}/${this.userEntId}`});
                break;
            case 'AUD':
                this.$router.push({path: `/vodContent/${this.tkhId}/${this.itmId}/${this.resId}/${this.courseResource.moduleId}/${this.userEntId}`});
                break;
            case 'REF':
                this.$router.push({path: `/refContent/${this.userEntId}/${this.tkhId}/${this.itmId}/${this.resId}/${this.courseResource.moduleId}`});
                break;
            case 'SCO':
                //  path: '/scoPlayer/:userEntId/:itmId/:tkhId/:modId/:resId',
                this.$router.push({path: `/scoPlayer/${this.userEntId}/${this.itmId}/${this.tkhId}/${this.courseResource.moduleId}/${this.resId}`});
                break;
            }
        },
        reRatingConfirm() {
            this.reRatingTip = true;
        },
        reRating() {
            this.$router.replace({name: 'contents'});
            this.$parent.isLoading = true;
            this.$axios({
                method: 'GET',
                url: '/app/exam/reRating/' + this.courseResource.res_id
            }).then(res => {
                if (res.data.code === 301) {
                    this.tstErrorTips = true;
                    this.tipsType = this.$t('has_deleted_learning_record'); //报名记录被删除
                } else if (res.data.code === 500) {
                    //this.tstErrorTips = true;
                    //this.tipsType = this.$t('exam_rpt_rerating_error');
                    //this.reRatingTip = false;
                    //this.$parent.$parent.isLoading = true;
                } else {
                    this.tipsType = this.$t('exam_rpt_rerating_sussess');
                    this.courseResource.isMarkStatus = false;
                    //刷新页面
                }
            });
        },
        beforeLearn(type) {
            /*当不显示按钮，改选中框点击无效*/
            if (this.courseResource.traineeTestDetailDTO && this.courseResource.traineeTestDetailDTO.managedInd && !this.courseResource.traineeTestDetailDTO.startedInd) {
                Toast({message: this.$t('exam_not_start'), forbidClick: true});
                return;
            }
            if (!this.isShowLearnBtn()) {
                return;
            }
            if (this.courseResource.rrqModTitle && this.courseResource.isRrqDone !== null && this.courseResource.isRrqDone !== false) { //是否完成先修模块
                if (this.courseResource.isRrqDone) { // 判断先修课程
                    //     this.preInfoTip = true;
                    var objModStatus = this.courseResource.rrqStatus;
                    var objModType = this.courseResource.rrqModType;
                    if (objModType === 'SCO' || objModType === 'RDG' || objModType === 'VOD' || objModType === 'AICC_AU' || objModType === 'REF' || objModType === 'SCLASS') {
                        if (objModStatus === 'I') {
                            this.tipsType = this.$t('mod_prep_requeid_attempt_1') + `「${this.courseResource.rrqModTitle}」` + this.$t('mod_prep_requeid_attempt_2'); //您必须先查阅才能学习该模块
                        } else {
                            this.tipsType = this.$t('mod_prep_requeid_cp') + `「${this.courseResource.rrqModTitle}」` + this.$t('mod_prep_requeid_attempt_2'); //您必须先完成才能学习该模块
                        }
                    } else if (objModType === 'SVY') {
                        this.tipsType = this.$t('mod_prep_requeid_submit') + `「${this.courseResource.rrqModTitle}」` + this.$t('mod_prep_requeid_attempt_2'); //您必须先提交才能学习该模块
                    } else {
                        if (objModStatus === 'I') {
                            this.tipsType = this.$t('mod_prep_requeid_submit') + `「${this.courseResource.rrqModTitle}」` + this.$t('mod_prep_requeid_attempt_2'); //您必须先提交才能学习该模块
                        } else if (objModStatus === 'P' || objModStatus === 'C') {
                            this.tipsType = this.$t('mod_prep_requeid_cp') + `「${this.courseResource.rrqModTitle}」` + this.$t('mod_prep_requeid_attempt_2'); //您必须先完成才能学习该模块
                        }
                    }
                    this.tstErrorTips = true;
                    this.examDoing = true;
                    return false;
                }
            }
            const req = {
                itmId: this.itmId,
                modId: this.courseResource.moduleId
            };
            if (this.tkhId) {
                req.tkhId = this.tkhId;
            }
            this.$axios({
                method: 'GET',
                url: '/app/api/trainee/course/module/beforeLearn',
                params: req
            }).then(res => {
                if (res.data.errCode !== 'success') {
                    this.tipsType = res.data.errMsg;
                    this.tstErrorTips = true;
                    return false;
                }
                if (res) {
                    this.beforeStart(type);
                }
            }).catch(error => {
                if (error.keyList) {
                    const courseList = error.keyList.toString();
                    const tips = error.message + `【${courseList}】`;
                    this.tipsType = tips;
                    this.tstErrorTips = true;
                }
            });
        },
        // 人脸信息采集 - 校验人脸信息是否可用：进入认证培训课程详情之前需要校验人脸信息是否可用
        beforeStart(type) {
            if (type === 'VOD' || type === 'DXT' || type === 'TST') {
                this.$axios({
                    method: 'GET',
                    url: `/app/api/trainee/user-face-gather/check-user-face`,
                    params: {
                        busId: this.modResId,
                        type: 'ONLINE_COURSE'
                    }
                }).then(res => {
                    if (res.data.code === '500') {
                        Toast({message: res.data.msg, forbidClick: true});
                    } else {
                        this.start(type);
                    }
                }).catch(err => {
                    console.log('err:---', err.response.data);
                });
            } else {
                this.start(type);
            }
        },
        start(type) {
            /*当不显示按钮，改选中框点击无效*/
            if (!this.isShowLearnBtn()) {
                return;
            }
            let {resources} = this.list;
            /*时间超过的时候*/
            if (!this.courseResource.isValidity) {
                this.tipsType = this.$t('online_module_end');
                this.tstErrorTips = true;
            }
            switch (type) {
            case 'ASS':
                /*作业评分状态 I表示进行评分中 其他状态表示已评分*/
                // if (this.courseResource && this.courseResource.movStatus === 'I') {
                //     this.tstErrorTips = true;
                //     this.tipsType = this.$t('mod_tips_1'); //您的作业正在评分中，不可重复提交
                // } else if (this.coloring()) { // 判断提交那些是否满足
                //     this.tstErrorTips = true;
                //     this.tipsType = this.$t('mod_tips_2'); //您的作业已提交，不可重复提交
                // } else {
                //     this.$router.push({path: `/assWork/${this.tkhId}/${this.modResId}`});
                // }
                if (compareDate(this.courseResource.beginTime)) { //开始时间判断
                    this.tstErrorTips = true;
                    this.tipsType = this.$t('mod_start_err'); //您的作业已提交，不可重复提交
                    return false;
                }
                if (this.courseResource.dueTime && !compareDate(this.courseResource.dueTime)) { //结束时间判断
                    this.tstErrorTips = true;
                    this.tipsType = this.$t('mod_end_err'); //您的作业已提交，不可重复提交
                    return false;
                }
                if (!compareDate(this.courseResource.endTime)) { //结束时间判断
                    this.tstErrorTips = true;
                    this.tipsType = this.$t('mod_end_err'); //您的作业已提交，不可重复提交
                    return false;
                }
                if (this.coloring()) {
                    this.tstErrorTips = true;
                    this.tipsType = this.$t('mod_tips_2'); //您的作业已提交，不可重复提交
                    return false;
                }
                this.$axios({
                    method: 'GET',
                    url: `/app/api/trainee/course/module/detail`,
                    params: {
                        itmId: this.itmId,
                        modId: this.modResId
                    }
                }).then(res => {
                    this.$router.push({path: `/assWork/${this.tkhId}/${this.modResId}/${this.itmId}`});
                }).catch(() => {
                    this.tstErrorTips = true;
                    this.tipsType = this.$t('mod_tips_2'); //您的作业已提交，不可重复提交
                });
                break;
            case 'DXT':
            case 'TST':
                if (this.examDoing) {
                    this.examDoing = false;
                    if (this.coloring()) { //已达到最大允许打开次数 或者已经提交
                        let resource = this.courseResource.traineeTestDetailDTO;
                        if ((this.courseResource.traineeTestDetailDTO.totalOpen && this.courseResource.traineeTestDetailDTO.maxUsrOpen !== 0 && (this.courseResource.traineeTestDetailDTO.totalOpen >= this.courseResource.traineeTestDetailDTO.maxUsrOpen))) {
                            this.tipsType = this.$t('mod_tips_4'); //您已达到该测验指定的最大打开次数
                        } else if ((this.courseResource.traineeTestDetailDTO.totalAttempt && this.courseResource.traineeTestDetailDTO.maxUsrAttempt !== 0 && (this.courseResource.traineeTestDetailDTO.totalAttempt >= this.courseResource.traineeTestDetailDTO.maxUsrAttempt))) {
                            this.tipsType = this.$t('mod_tips_11'); //您已达到该测验指定的最大提交次数
                        } else if (this.courseResource && this.courseResource.movStatus === 'P' && resource.submitAfterPass === 1) {
                            this.tipsType = this.$t('mod_tips_3'); //测验已合格，不能再进行测验
                        }
                        this.tstErrorTips = true;
                        this.examDoing = true;
                    } else {
                        let tkhId = this.tkhId;
                        let modId = this.modResId;
                        // 判断是否再评分
                        this.$axios({
                            method: 'GET',
                            url: `/app/module/check-test-prev`,
                            params: {
                                modId: modId
                            }
                        }).then(res => {
                            //会返回次数和测试时间是否结束的标志
                            if (res.data.modStartedInd) {
                                this.examBeforeTips = true;
                                let count = 0;
                                let interval = setInterval(() => {
                                    if (this.examInfo.id || count >= 20) {
                                        clearInterval(interval);
                                        // 提醒获取试卷失败，关闭提示框
                                        this.examBeforeTips = false;
                                        this.examTip = !!this.examInfo.id;
                                        this.examDoing = !!this.examInfo.id;
                                        if (count >= 20) {
                                            this.tipsType = this.$t('get_test_paper_error'); // 试卷正在生成中，请三分钟之后重试
                                            this.tstErrorTips = true;
                                            this.examDoing = true;
                                        }
                                    } else {
                                        this.getTestPaper(modId);
                                    }
                                    count++;
                                }, 3000);
                            }
                        }).catch((error) => {
                            if (error.response) {
                                this.tipsType = error.response.data.errMsg;
                                this.tstErrorTips = true;
                            } else if (error.request) {
                                this.tipsType = error.request.data.errMsg;
                                this.tstErrorTips = true;
                            } else {
                                this.tipsType = error.message.data.errMsg;
                                this.tstErrorTips = true;
                            }
                            this.examDoing = true;
                        });
                    }
                }
                break;
            case 'RDG': //教材
                if (['C', 'F', 'W'].includes(this.$store.getters.getDetail.learnerStatus)) {
                    this.reviewPopupLayer = true;
                    this.moduleType = 'RDG';
                } else {
                    this.jumpModuleDetail('RDG');
                }
                break;
            case 'VOD': //视频点播
                if (['C', 'F', 'W'].includes(this.$store.getters.getDetail.learnerStatus)) {
                    this.reviewPopupLayer = true; // 回顾提示
                    this.moduleType = 'VOD';
                } else {
                    this.jumpModuleDetail('VOD');
                }
                break;
            case 'AUD': //音频
                if (['C', 'F', 'W'].includes(this.$store.getters.getDetail.learnerStatus)) {
                    this.reviewPopupLayer = true; //回顾提示
                    this.moduleType = 'AUD';
                } else {
                    this.jumpModuleDetail('AUD');
                }
                break;
            case 'SCO': //scorm课件
                if (['C', 'F', 'W'].includes(this.$store.getters.getDetail.learnerStatus)) {
                    this.reviewPopupLayer = true;
                    this.moduleType = 'SCO';
                } else {
                    this.jumpModuleDetail('SCO');
                }
                break;
            case 'REF': //参考
                if (['C', 'F', 'W'].includes(this.$store.getters.getDetail.learnerStatus)) {
                    this.reviewPopupLayer = true;
                    this.moduleType = 'REF';
                } else {
                    this.jumpModuleDetail('REF');
                }
                break;
            case 'SCLASS': //微课
                if (['C', 'F', 'W'].includes(this.$store.getters.getDetail.learnerStatus)) {
                    this.reviewPopupLayer = true;
                    this.moduleType = 'REF';
                } else {
                    this.jumpModuleDetail('SCLASS');
                }
                break;
            case 'SVY': //课程评估问卷
                //if (!mov || (mov && mov.mov_status !== 'C' && mov.mov_status !== 'P')) {
                if ((this.courseResource.movStatus !== 'C' && this.courseResource.movStatus !== 'P')) {
                    this.$router.push({path: `/detail/${this.modResId}/course`});
                } else if (this.courseResource.movStatus === 'C') {
                    this.tstErrorTips = true;
                    this.tipsType = this.$t('mod_tips_7'); //您已经提交了该课程评估问卷
                }
                break;
            case 'ACE': //课后调查问卷
                //if (!mov || (mov && mov.mov_status !== 'C' && mov.mov_status !== 'P')) {
                if ((this.courseResource.movStatus !== 'C' && this.courseResource.movStatus !== 'P')) {
                    this.$axios({
                        url: `/app/api/trainee/course/lesson/evalList`,
                        method: 'GET',
                        params: {modId: this.modResId, itmId: this.itmId}
                    }).then(res => {
                        if (res.status === 200) {
                            if (res.data.length > 0) {
                                this.$router.push({path: `/unitList/${this.itmId}/${this.modResId}`});
                            } else {
                                this.$router.push({path: `/aceDetail`, query: {itmId: this.itmId, modId: this.modResId, operation: 2}});
                            }
                        }
                    });
                    // this.$router.push({path: `/detail/${this.courseResource.res_id}/course`});
                } else if (this.courseResource.movStatus === 'C') {
                    this.tstErrorTips = true;
                    this.tipsType = this.$t('mod_tips_7'); //您已经提交了该课程评估问卷
                }
                break;
            }
        },
        //学习单元需完成状态
        getStatus(subtype, status) {
            if (subtype === 'RDG' || subtype === 'REF' || subtype === 'VOD') { //教材、参考、视频点播
                if (status === 'IFCP') {
                    return this.$t('mod_need_view');//"需查阅"
                } else if (status === 'UNLIMITED') {
                    return this.$t('cos_app_noNeed');
                } else {
                    return this.$t('mod_need_complete'); //"需完成";
                }
            } else if (subtype === 'SVY') { //课程评估问卷
                if (status === 'CP') {
                    return this.$t('mod_need_submit');//需提交
                } else if (status === 'UNLIMITED') {
                    return this.$t('cos_app_noNeed');
                }
            } else if (subtype === 'ASS' || subtype === 'TST' || subtype === 'DXT') { //作业、静态测验、动态测验
                if (status === 'IFCP') {
                    return this.$t('mod_need_submit');//"需提交"
                } else if (status === 'UNLIMITED') {
                    return this.$t('cos_app_noNeed');
                } else {
                    return this.$t('mod_need_pass'); //"需合格";
                }
            } else { //subtype === 'SCO'、SCORM课件
                if (status === 'IFCP') {
                    return this.$t('mod_need_attempt');//"需尝试"
                } else if (status === 'UNLIMITED') {
                    return this.$t('cos_app_noNeed');
                } else {
                    return this.$t('mod_need_complete'); //"需完成";
                }
            }
        },
        coloring() {
            let {resources} = this.list;
            // let {mov, mod} = resources;
            // if (!mov) {
            //     return false;
            // }
            let resource = this.courseResource.traineeTestDetailDTO;
            switch (this.resSubType) {
            case 'TST':
            case 'DXT':
                //已到最大提交次数或最大打开次数
                if ((this.courseResource && resource && (resource.maxUsrAttempt !== 0 && (resource.totalAttempt >= resource.maxUsrAttempt))) || ((resource.maxUsrOpen !== 0 && (resource.totalOpen >= resource.maxUsrOpen)))) {
                    return true;
                } else if (this.courseResource && this.courseResource.movStatus === 'P' && resource.submitAfterPass === 1) {
                    return true;
                }
                break;
            case 'ASS':
                /*如果有提交时间*/
                if (this.courseResource.modAssSubmit) {
                    return true;
                }
                break;
            case 'ACE':
                // 已提交课后问卷
                if (this.courseResource.movStatus === 'C') {
                    return true;
                }
                break;
            }
            if (this.courseResource.rrqModTitle && this.courseResource.isRrqDone !== null && this.courseResource.isRrqDone !== false) {
                return true;
            } else if (this.courseResource.isValidity === false) {
                return true;
            }
        },
        subTime(value) { //yyyy-MM-dd HH:mm
            if (value) {
                return value.substring(0, value.indexOf(':', value.indexOf(':') + 1));
            } else {
                return value;
            }
        },
        unfold() {
            this.moreList = !this.moreList; //展开每个学习单元的详情
        },
        getAppStatusStr(movStatus, type) { //每个学习单元的状态
            if (!movStatus) return '';
            if (movStatus === 'I') {
                if ((type === 'ASS' || type === 'TST' || type === 'DXT') && (this.courseResource) && this.courseResource.submitTime) {
                    return this.$t('cos_app_inprogress'); //评分中
                } else if (type === 'VOD' || type === 'RDG' || type === 'FAQ' || type === 'GLO' || type === 'REF' || type === 'SCLASS' || type === 'AUD' || type === 'SCO') {
                    return this.$t('cos_app_I_V'); //已查阅
                } else {
                    return this.$t('cos_app_inprogress'); //进行中
                }
            } else if (movStatus === 'N') {
                return this.$t('cos_app_N_scorm'); //未尝试
            } else if (movStatus === 'C' && (type === 'SVY' || type === 'ACE')) {
                return this.$t('cos_app_S'); //已提交
            } else if (movStatus === 'C') {
                return this.$t('cos_app_completed'); //已完成
            } else if (movStatus === 'F') {
                if (type === 'TST' || type === 'DXT' || type === 'ASS') {
                    return this.$t('cos_app_flunk'); //fail,不合格
                } else {
                    return this.$t('cos_app_fail'); //fail,未完成
                }
            } else if (movStatus === 'B') {
                return this.$t('cos_app_B_scorm');
            } else if (movStatus === 'P') {
                if (type === 'TST' || type === 'DXT' || type === 'ASS') {
                    return this.$t('cos_app_passed'); //passed,已合格
                } else {
                    return this.$t('cos_app_P'); //pass,已通过
                }
            } else if (movStatus === 'W') {
                return this.$t('cos_app_withdrawn'); //已放弃
            } else if (movStatus === 'notapp') {
                return this.$t('cos_app_notapp'); //未报名
            } else if (movStatus === 'pending') {
                return this.$t('cos_app_pending'); //审批中
            } else if (movStatus === 'admitted') {
                return this.$t('cos_app_admitted'); //已报名
            } else if (movStatus === 'rejected') {
                return this.$t('cos_app_admitted'); //已报名
            } else if (movStatus === 'waiting') {
                return this.$t('cos_in_wait_list'); //等待队列
            } else {
                return this.$t('cos_app_notapp'); //未报名
            }
        },
        testReportBtn() { //测试报告
            if (this.resSubType === 'TST' || this.resSubType === 'DXT') {
                if (this.unregistered && this.courseResource.submitTime && this.courseResource.traineeTestDetailDTO.totalAttempt > 0) {
                    return true;
                }
                return false;
            }
        },
        // reRatingBtn() { //重新评分
        //     return this.courseResource.isMarkStatus;
        // },
        formatSecToTime(sec) { //时长转换
            var min = 0;
            var hour = 0;
            if (sec > 0) {
                //分
                if (sec >= 60) {
                    min = Math.floor(sec / 60);
                    sec = (sec % 60);
                }
                //时
                if (min >= 60) {
                    hour = Math.floor(min / 60);
                    min = min % 60;
                }
                if (hour < 10) {
                    hour = '0' + hour;
                }
                if (min < 10) {
                    min = '0' + min;
                }
                if (sec < 10) {
                    sec = '0' + sec;
                }
            }
            return hour + ':' + min + ':' + sec; //秒数取整，四舍五入
        },
        formatTime(time) { //时长转换
            var sec = time * 60;
            var min = 0;
            var hour = 0;
            if (sec > 0) {
                //分
                if (sec >= 60) {
                    min = Math.floor(sec / 60);
                    sec = Math.floor(time * 60 - min * 60);
                } else {
                    sec = Math.floor(sec);
                }
                //时
                if (min >= 60) {
                    hour = Math.floor(min / 60);
                    min = min % 60;
                }
                if (hour < 10) {
                    hour = '0' + hour;
                }
                if (min < 10) {
                    min = '0' + min;
                }
                if (sec < 10) {
                    sec = '0' + sec;
                }
            }
            return hour + ':' + min + ':' + sec; //秒数取整，四舍五入
        },
        requiredTime(sec) {
            var min = 0;
            if (sec > 0) {
                if (sec >= 60) {
                    min = Math.floor(sec / 60);
                    sec = (sec % 60 / 60);
                }
                min = min + sec;
            }
            return min;
        },
        /**
         * 检查未完成 已放弃 已完成状态 （测验，作业不可以查看）
         * @returns {boolean}
         */
        isShowLearnBtn() {
            let status = true;
            if (['C', 'F', 'W'].includes(this.$store.getters.getDetail.learnerStatus)) {
                switch (this.resSubType) {
                case 'DXT':
                case 'ASS':
                case 'ACE':
                case 'TST':
                case 'SVY':
                    status = false;
                    break;
                }
            }
            return status;
        },
        _wbModuleGetTime(datetime) {
            let month = 0;
            let day = 0;
            let hour = 0;
            let minutes = 0;
            let seconds = 0;
            if (datetime.getMonth() > 9) {
                month = datetime.getMonth() + 1;
            } else {
                month = '0' + (datetime.getMonth() + 1);
            }
            if (datetime.getDate() > 9) {
                day = datetime.getDate();
            } else {
                day = '0' + datetime.getDate();
            }

            if (datetime.getHours() > 9) {
                hour = datetime.getHours();
            } else {
                hour = '0' + (datetime.getHours() + 1);
            }

            if (datetime.getMinutes() > 9) {
                minutes = datetime.getMinutes();
            } else {
                minutes = '0' + datetime.getMinutes();
            }

            if (datetime.getSeconds() > 9) {
                seconds = datetime.getSeconds();
            } else {
                seconds = '0' + datetime.getSeconds();
            }

            let time = datetime.getFullYear() + month + day + hour + minutes + seconds;
            return time;
        },
        getAiccUrl(scoVer) {
            var result = null;
            var servlet = '';
            if (scoVer && scoVer === '2004') {
                servlet = 'SCO2004CMI';
            } else {
                servlet = 'CMI';
            }

            var virtualPathLoc = self.location.pathname.indexOf('/app/');
            if (virtualPathLoc === -1) {
                virtualPathLoc = self.location.pathname.indexOf('/servlet/');
            }
            result = encodeURIComponent('/app/module/cmi?');
            return result;
        },
        getAiccSid(entId, cosId, modId, tkhId) {
            var today = new Date();
            today = this._wbModuleGetTime(today);
            let modVendor = '';
            let aiccSid = null;
            if (entId && cosId && modId && tkhId) {
                aiccSid = escape(entId + ':_:_:' + cosId + ':_:_:' + modId + ':_:_:' + modVendor + ':_:_:' + today + ':_:_:' + tkhId + ':_:_:');
            } else {
                aiccSid = 'VIEWONLY';
            }
            return aiccSid;
        },
        getCosUrl(srcLink, modId, tkhId, scoVersion) {
            let url = '';
            if (srcLink.indexOf('../') >= 0) {
                srcLink = '/' + srcLink.substring(srcLink.lastIndexOf('../') + 3, srcLink.length);
            }

            if (scoVersion === '2004') {
                //thisURL="url=courses/course1/imsmanifest.xml&cid=21321123&uid=test01";
                //url为课件根目录下的imsmanifest.xml；cid为整个课件ID；uid为学员ID；
                //如果没有url，不能够打开课件；如果没有cid或uid，则为浏览模式，非正常学习；
                url = '..' + escape(srcLink) + '?cid=' + modId + '&uid=' + tkhId;
            } else {
                url = escape(this.appUrl + srcLink);
            }
            return url;
        },
        downloadStatusDesc(modId) {
            let modObj = this.getDownloadCourseModTask(modId);
            if (modObj) {
                if (modObj.status === 'completed') {
                    return this.$t(modObj.statusLabel);
                } else {
                    return this.$t(modObj.statusLabel) + ' ' + modObj.percentage;
                }
            } else {
                return this.$t('lab_download');
            }
        },
        /**
         * 获取试卷信息
         * @param modId
         */
        getTestPaper(modId) {
            this.$axios({
                method: 'GET',
                url: `/app/exam/cache/info`,
                params: {
                    examId: modId,
                    subId: 0
                }
            }).then(res => {
                if (res.data.id) {
                    this.examBeforeTips = false;
                    this.examTip = true;
                    this.examDoing = true;
                    this.examList = res.data.questions;
                    this.questionType = res.data.questionType;
                }
                this.examInfo = res.data;
            });
        }
    },
    computed: {
        rcov() {
            return this.$store.getters.getDetail;
        },
        courseResource() {
            return this.list.moduleBaseDTO;
        },
        modResId() {
            return this.list.moduleBaseDTO.moduleId; // 之前是res_id 大概率是moduleId
        },
        resSubType() {
            return this.list.moduleBaseDTO.modType; // 类型
        },
        /*这两个参数不用了*/
        // mod() {
        //     return this.list.resources ? this.list.resources.mod : {};
        // },
        // mov() {
        //     return this.list.resources ? this.list.resources.mov : {};
        // },
        getDownloadCourseModTask() {
            //下载任务信息
            return function(modId) {
                let modObj = this.$store.getters.getDownloadCourseModTask(modId);
                if (modObj === null || modObj === undefined || modObj === '') {
                    return null;
                } else {
                    return modObj;
                }
            };
        }
    },
    mounted() {
        this.modSubmitType = this.courseResource.modSubmitType;
    }
};
</script>

<style scoped lang="less">
    @import "./courseLess.less";
    .learning-icon-box {
        width: 70px;
        .start-learning-icon {
            width: 30px;
            height: 30px;
            background: #eeeeee;
            border-radius: 50%;
            display: inline-block;
            margin: 0 0 0 20px;
            &:before {
                content: "";
                display: block;
                width: 9px;
                height: 13px;
                background: url(./images/course-icon.png) -2px -695px;
                background-size: 14px;
                margin: 8px auto 0;
            }
            &.cur:before {
                content: "";
                background-position: -2px -75px;
                background-size: 12px;
            }
        }
    }
    .satisfy-icon:before {
        content: "";
        display: inline-block;
        width: 12px;
        height: 12px;
        background: url(./images/course-icon.png) no-repeat 0 -21px;
        background-size: 12px;
        margin: 0 5px -1px 0px;
    }
    .satisfy-icon.cur:before {
        content: "";
        background-position: 0 -39px;
        background-size: 12px;
    }
    .box-padding-01 {
        padding: 0 0 0 40px;
    }
    .box-padding-02 {
        padding: 5px 0 0 40px;
    }
    .box-padding-03 {
        padding: 20px 0 0 40px;
    }
    .margin-top30 p {
        margin-top: 15px;
    }
    .download {
        color: #075ebb;
    }
    .re-rating-btn {
        line-height: 20px;
        background: #f7a900;
        color: #fff;
        border-radius: 3px;
        display: inline-block;
        float: right;
    }
    .exam-dialog {
        /deep/.van-dialog__header {
            font-size: 20px;
            text-align: initial;
            padding: 30px 40px 20px;
        }
    }
</style>
